<template>
	<view class="pages">
		<!-- 头部 -->
		<view class="header_bar header_fixed">
			<view class="header">
				<view class="header-goBack" @tap.stop="$tools.back(1)"></view>
				<view class="header-title">重置密码</view>
			</view> 
		</view> 
		
		<view class="">
			<view class="operateBox-tabs operateBox-tabs--top">
				<view class="operateBox-flex">
					<view class="operateBox-formBox-list-header">
						<image class="operateBox-formBox-list-icon" src="../../static/operate/phone.png" mode=""></image>
					</view>
					<view class="operateBox-formBox-list" :class="{ 'operateBox-formBox-list-input--active': isFocus == 1, showCloseBtn: phone != '' }">
						<input type="text" placeholder="请输入手机号" v-model="phone" placeholder-class="inputStyle"
						@blur="blurInput(1)"
						@focus="focusInput(1)"/>
						<view class="operateBox-formBox-list-image">
							<view class="operateBox-formBox-list-image__clear operateBox-formBox-list-image__clear--active" @click="clearData('phone')">
								<image src="../../static/public/icon-clear.png" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="operateBox-flex">
					<view class="operateBox-formBox-list-header">
						<image class="operateBox-formBox-list-icon" src="../../static/operate/icon-code.png" mode=""></image>
					</view>
					<view class="operateBox-formBox-list " :class="{ 'operateBox-formBox-list-input--active': isFocus == 2, showCloseBtn: code != '' }">
						<input type="number" placeholder="请输入短信验证码" v-model="code" placeholder-class="inputStyle"
						@blur="blurInput(2)"
						@focus="focusInput(2)"/>
						<view class="operateBox-formBox-list-image">
							<view class="operateBox-formBox-list-image__clear operateBox-formBox-list-image__clear--active" @click="clearData('code')">
								<image src="../../static/public/icon-clear.png" mode="widthFix"></image>
							</view>
							<view class="operateBox-formBox-list-image__code" @click="sendCode()">
								<text class="code">{{ remain }}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="operateBox-flex">
					<view class="operateBox-formBox-list-header">
						<image class="operateBox-formBox-list-icon" src="../../static/operate/password.png" mode=""></image>
					</view>
					<view class="operateBox-formBox-list" :class="{ 'operateBox-formBox-list-input--active': isFocus == 4, showCloseBtn: password != '' }">
						<input placeholder="设置登录密码" placeholder-class="inputStyle" v-model="password"
						:password="!eyeShowHideArray[4].show"
						@blur="blurInput(4)"
						@focus="focusInput(4)"/>
						<view class="operateBox-formBox-list-image">
							<view class="operateBox-formBox-list-image__see" @click="toggleEyeStatus(4)">
								<image :src="eyeShowHideArray[4].show ? eyeShow : eyeHide" mode="widthFix"></image>
							</view>
							<view class="operateBox-formBox-list-image__clear operateBox-formBox-list-image__clear--active" @click="clearData('password')">
								<image src="../../static/public/icon-clear.png" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="operateBox-flex">
					<view class="operateBox-formBox-list-header">
						<image class="operateBox-formBox-list-icon" src="../../static/operate/password.png" mode=""></image>
					</view>
					<view class="operateBox-formBox-list" :class="{ 'operateBox-formBox-list-input--active': isFocus == 3, showCloseBtn: re_password != '' }">
						<input placeholder="确认登录密码" placeholder-class="inputStyle" v-model="re_password"
						:password="!eyeShowHideArray[3].show"
						@blur="blurInput(3)"
						@focus="focusInput(3)"/>
						<view class="operateBox-formBox-list-image">
							<view class="operateBox-formBox-list-image__see" @click="toggleEyeStatus(3)">
								<image :src="eyeShowHideArray[3].show ? eyeShow : eyeHide" mode="widthFix"></image>
							</view>
							<view class="operateBox-formBox-list-image__clear operateBox-formBox-list-image__clear--active" @click="clearData('re_password')">
								<image src="../../static/public/icon-clear.png" mode="widthFix"></image>
							</view>
							<!-- <view class="operateBox-formBox-list-image__see" @click="toggleEyeStatus(3)">
								<image :src="eyeShowHideArray[3].show ? eyeShow : eyeHide" mode="widthFix"></image>
							</view> -->
						</view>
					</view>
				</view>
				<view class="firstBox-bottom">
					<!-- <image @tap.stop="checkArgee()" class="firstBox-bottom-img" :src="isAgree ? '../../static/public/check-active.png' : '../../static/public/check.png'" mode=""></image>
					<view class="firstBox-bottom-title">同意</view>
					<view class="firstBox-bottom-title-choice" @tap.stop="$tools.jump('./information',1)">《平台服务协议》</view>
					<view class="firstBox-bottom-title">和</view>
					<view class="firstBox-bottom-title-choice" @tap.stop="$tools.jump('./information',2)">《隐私政策》</view> -->
				</view>
				<view class="initBtn initBtn--top" @tap.stop="$u.throttle(confirm,1000)">提交</view>
				<view class="operateBox-btn--m">
					<view class="operateBox-btn-title" @tap.stop="$tools.back(1)"><text class="red">立即登录</text></view>
					</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		components:{
		},
		data(){
			return{
				phone: '',
				code: '',
				re_password: '',
				password: '',
				// 验证码
				remain: '获取验证码',
				isSend: true,
				time: 60,
				timer: null,
				isFocus: null,
				eyeShow: '../../static/public/icon-eye-open.png',
				eyeHide: '../../static/public/icon-eye-close.png',
				eyeShowHideArray: [{ show: false }, { show: false }, { show: false }, { show: false }, { show: false }],
				isAgree: false,
				account:'',
				showChildren:false, // 是否是子账号
			}
		},
		onLoad() {
			
		},
		onShow() {
		},
		methods: {
			confirm(){
				let that = this;
				if (that.phone == '' ) {
					return that.$tools.toast('请输入手机号');
				}
				if (that.phone.length!=11 || !/^((1[0-9])+\d{9})$/.test(that.phone)){
					return that.$tools.toast('请输入正确的手机号码！！！');
				}
				// if(that.phone.indexOf("@") >-1){
				// 	if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/g.test(that.phone)){
				// 		return that.$tools.toast('请输入正确的邮箱！！！');
				// 	}
				// }
				if (that.code == ''){
					return that.$tools.toast('请输入短信验证码');
				}
				if (that.password == '' ) {
					return that.$tools.toast('设置登录密码');
				}	
				var reg = /^(?![0-7]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
				if(!reg.test(that.password)){
					return that.$tools.toast('请输入6-12位字母+数字的密码');
				}
				if (that.re_password == '' ) {
					return that.$tools.toast('确认登录密码');
				}
				if (that.re_password != that.password ) {
					return that.$tools.toast('两者密码不一致');
				}
				var data = {};
				data['account'] = that.phone;
				data['type'] = 1;
				data['code'] = that.code;
				data['newPwd'] = that.$md5(that.password);
				data['twoPwd'] = that.$md5(that.re_password);
				console.log("data：",data);
				uni.showLoading({
					mask: true
				});
				that.$Ajax('/api/user/forgetPwd',data,res => {
						uni.hideLoading();
						if (res.code == 200) {
							that.$tools.toastJump('重置密码成功','./login');
						}
					}
				)
			},
			sendCode(){
				if (this.phone == '' ) {
					return this.$tools.toast('请输入手机号');
				}
				if (this.phone.length!=11 || !/^((1[0-9])+\d{9})$/.test(this.phone)){
					return this.$tools.toast('请输入正确的手机号码！！！');
				}
				if(this.isSend == true){
					uni.showLoading({
						title: '发送中',
						mask: true
					});
					var data = {};
					data['account'] = this.phone;
					data['type'] = 3;
					console.log("data：",data);
					this.$Ajax('/api/user/sendCode',
					data,
					res => {
							this.isSend = false;
							this.remain = this.time + 's';
							this.timer = setInterval(() => {
								this.time--;
								this.remain = this.time + 's';
								if (this.time == 0) {
									clearInterval(this.timer);
									this.remain = '重新获取';
									(this.isSend = true), (this.time = 60);
								}
							}, 1000);
						}
					)
					uni.hideLoading();
				}
			},
			checkArgee(){
				this.isAgree = !this.isAgree;
			},
			/* clear & eye */
			focusInput(index) {
				this.isFocus = index;
			},
			blurInput(index) {
				this.isFocus = null;
			},
			clearData(keyName) {
				for (var key in this.$data) {
					if (key == keyName) {
						this.$data[key] = '';
					}
				}
			},
			toggleEyeStatus(index) {
				this.eyeShowHideArray[index].show = !this.eyeShowHideArray[index].show;
			}
		}
	}
</script>

<style lang="scss" scoped>
.pages{
	background: #fff;
}
	@import '@/common/scss/pages/operate/register';
	.operateBox-flex{
		border-radius: 0;
		border-bottom: 1px solid #ebebeb;
		background: none;
	}
</style>